{% extends "base.html" %}
{% comment 'header' %}
# This file is part of opentaps Smart Energy Applications Suite (SEAS).

# opentaps Smart Energy Applications Suite (SEAS) is free software:
# you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# opentaps Smart Energy Applications Suite (SEAS) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public License
# along with opentaps Smart Energy Applications Suite (SEAS).
# If not, see <https://www.gnu.org/licenses/>.
{% endcomment %}

{% load django_tables2 %}
{% load static i18n %}
{% load fmttime_str from core_tags %}
{% block title %}Weather Station: {{ object }}{% endblock %}

{% block content %}
<div class="container">

  <div class="card mb-3">
    <div class="card-body">
      <h2 class="d-flex">
        <span>
        {% block section_title %}
        {% if object.station_name %}
          Weather Station {{ object.station_name }} <span style="font-size: 1rem;">({{ object.weather_station_code | default:object.weather_station_id }})</span>
        {% else %}
          Weather Station {{ object }}
        {% endif %}
        {% endblock section_title %}
        </span>
        {% block add_button %}
        <div class="ml-auto text-nowrap">
          <a href="{% url 'core:weather_station_fetch_data' object.weather_station_id %}" role="button" class="btn btn-primary"><i class="fas fa-cloud-download-alt"></i> Fetch Data</a>
        </div>
        {% endblock add_button %}
      </h2>
      <br/>

      {% block inner_content %}

      <div class="row">
        <div class="col-md">
          <table class="ml-md-4 mb-4">
            <tr>
              <td>USAF ID:</td>
              <td>{{ object.weather_station_code | default:'n/a' }}</td>
            </tr>
            <tr>
              <td>Name:</td>
              <td>{{ object.station_name | default:'n/a' }}</td>
            </tr>
            <tr>
              <td>Country:</td>
              <td>{{ object.country | default:'n/a' }}</td>
            </tr>
            <tr>
              <td>Latitude:</td>
              <td>{{ object.latitude | default:'n/a' }}</td>
            </tr>
            <tr>
              <td>Longitude:</td>
              <td>{{ object.longitude | default:'n/a' }}</td>
            </tr>
            <tr>
              <td>Elevation:</td>
              <td>{{ object.elevation }}</td>
            </tr>
            {% if object.latest_reading %}
            <tr>
              <td>Latest data:</td>
              <td>{{ object.latest_reading.as_of_datetime|fmttime_str }}</td>
            </tr>
            {% endif %}
          </table>
        </div>
        <div class="col-md" style="min-height: 200px">
          {% include "core/_weather_station_geoview.html" with weather_station=object %}
        </div>
      </div>

      <p>
        {% include "core/_weather_history_chart.html" with weather_station_id=object.weather_station_id %}
      </p>
      {% endblock inner_content %}
    </div>
  </div>
</div>
{% endblock content %}
